#!/usr/bin/perl -w
#
#  customize-mapnik-map
#

use strict;
$ENV{MAPNIK_PREFIX} ||= "planet_osm";

open(IN, '<', 'osm-template.xml') or die;

while(<IN>) {
    s/%SYMBOLS_DIR%/$ENV{MAPNIK_SYMBOLS_DIR}/;
    s/%WORLD_BOUNDARIES_DIR%/$ENV{MAPNIK_WORLD_BOUNDARIES_DIR}/;
    s/%DBNAME%/$ENV{MAPNIK_DBNAME}/;
    s/%PREFIX%/$ENV{MAPNIK_PREFIX}/;

    if ($ENV{'MAPNIK_DBUSER'} eq '') {
        next if m|<Parameter name="user">%DBUSER%</Parameter>|
    } else {
	s/%DBUSER%/$ENV{MAPNIK_DBUSER}/;
    }

    if ($ENV{'MAPNIK_DBPASS'} eq '') {
        next if m|<Parameter name="password">%DBPASS%</Parameter>|
    } else {
	s/%DBPASS%/$ENV{MAPNIK_DBPASS}/;
    }

    if ($ENV{'MAPNIK_DBHOST'} eq '') {
        next if m|<Parameter name="host">%DBHOST%</Parameter>|
    } else {
        s/%DBHOST%/$ENV{MAPNIK_DBHOST}/;
    }
    if ($ENV{'MAPNIK_DBPORT'} eq '') {
        next if m|<Parameter name="port">%DBPORT%</Parameter>|
    } else {
        s/%DBPORT%/$ENV{MAPNIK_DBPORT}/;
    }

    print;
}

